<template>
  <div class="home-swipe">
    <van-search
      v-model="value"
      placeholder="请输入搜索关键词"
      input-align="center"
      @focus="onFocus"
      @search="onSearch"
    />
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in bannerData" :key="item.id">
        <!-- <img :src="item.picUrl" alt="" /> -->
        <van-image :src="item.imageUrl" lazy-load radius="20" />
      </van-swipe-item>
    </van-swipe>
  </div>
</template>

<script>
import { Toast } from "vant";
// import axios from "axios";
export default {
  data() {
    return {
      value: "",
      bannerData: [],
    };
  },
  created() {
    this.getBanner(); //调用网络请求的方法 获取数据
  },
  methods: {
    //写一个完成网络请求的方法
    getBanner() {
      // axios
      //   .get("/api/recommend/banner")
      //   .then((response) => {
      //     //成功
      //     console.log(response);
      //     let resData = response.data; //获取响应结果的数据
      //     if (resData.result == 100) {
      //       this.bannerData = resData.data;
      //     }
      //     console.log(this.bannerData);
      //   })
      //   .catch(function (error) {
      //     console.loge(error);
      //   });
      this.$request("get", "/banner").then((res) => {
        console.log(res);
        if (res.code === 200) {
          this.bannerData = res.banners;
        }
      });
    },
    // mounted() {
    //   this.getBanner();
    // },
    onFocus() {
      Toast("触发获得焦点事件");
    },
    onSearch(val) {
      Toast(val);
    },
  },
};
</script>

<style scoped>
/* .my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
} */
</style>

<style scoped>
/* .my-swipe .van-swipe-item img {
  width: 100%;
  border-radium: 1rem;
} */
</style>
